﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Media;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Speed_of_live_and_deed
{
    public partial class FrmMain : Form
    {
        Game game;
        SoundPlayer musicPlayer = new SoundPlayer(Properties.Resources.backmusic); //游戏背景音乐
        public FrmMain()
        {
            InitializeComponent();
        }

        private void gameArea_Load(object sender, EventArgs e)
        {
            //初始化
            game = new Game();
            game.gameChanged += Game_gameChanged;
            //关闭小按钮
            btnDiffculty.Enabled = false;
            btnOrdinary.Enabled = false;
            btnEasy.Enabled = false;
        }
        //重绘游戏
        private void Game_gameChanged()
        {
            if (game != null)
            {
                gameArea.Invalidate();
            }
        }
        //画图
        private void gameArea_Paint(object sender, PaintEventArgs e)
        {
            if (game!=null)
            {
                game.Draw(e.Graphics, this.gameArea.Size);
            }
        }
        //处理键盘
        private void FrmMain_KeyDown(object sender, KeyEventArgs e)
        {
            if (game!=null)
            {
                game.KeyDown(e.KeyCode.ToString());
            }
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {

        }

        private void btnStartGame_Click(object sender, EventArgs e)
        {
            //初始化
            game = new Game();
            game.gameChanged += Game_gameChanged;
            gameArea.Invalidate();
            //关闭大按钮
            btnStartGame.Enabled = false;
            //开启小按钮
            btnDiffculty.Enabled = true;
            btnOrdinary.Enabled = true;
            btnEasy.Enabled = true;
            //停止播放背景音乐
            musicPlayer.Stop();
        }

        private void btnAboutMe_Click(object sender, EventArgs e)
        {
            FrmAboutme frm =new FrmAboutme();
            frm.ShowDialog();
        }

        private void btnDiffculty_Click(object sender, EventArgs e)
        {
            //初始化
            game = new Game();
            game.gameChanged += Game_gameChanged;
            game.btnDiffculty_Click();
            //开启大按钮
            btnStartGame.Enabled = true;
            //关闭小按钮
            btnDiffculty.Enabled = false;
            btnOrdinary.Enabled = false;
            btnEasy.Enabled = false;
            //开始游戏
            game.Start();
            //循环播放背景音乐
            musicPlayer.PlayLooping();
        }

        private void btnOrdinary_Click(object sender, EventArgs e)
        {
            //初始化
            game = new Game();
            game.gameChanged += Game_gameChanged;
            game.btnOrdinary_Click();
            //开启大按钮
            btnStartGame.Enabled = true;
            //关闭小按钮
            btnDiffculty.Enabled = false;
            btnOrdinary.Enabled = false;
            btnEasy.Enabled = false;
            //开始游戏
            game.Start();
            //循环播放背景音乐
            musicPlayer.PlayLooping();
        }

        private void btnEasy_Click(object sender, EventArgs e)
        {
            //初始化
            game = new Game();
            game.gameChanged += Game_gameChanged;
            game.btnEasy_Click();
            //开启大按钮
            btnStartGame.Enabled = true;
            //关闭小按钮
            btnDiffculty.Enabled = false;
            btnOrdinary.Enabled = false;
            btnEasy.Enabled = false;
            //开始游戏
            game.Start();
            //循环播放背景音乐
            musicPlayer.PlayLooping();
        }
        private void btnhelp_Click(object sender, EventArgs e)
        {
            MessageBox.Show("按下屏幕下方的字母，警察会动起来的呦");
        }
    }
}
